package com.fenghongzhang.day005;

import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;


/**
 * A simple {@link Fragment} subclass.
 */
public class TopFragment extends Fragment {
    private EditText input;
    private Button sendMessage;
    public TopFragment() {
        // Required empty public constructor
    }

    public interface MyListenerTwo{
        void revicerMessage(Object s);
    }
    private MyListenerTwo myListenerTwo;


    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        //找到你的fragment
        //1,通过id
        myListenerTwo = (MyListenerTwo) getFragmentManager().findFragmentByTag("buttom");
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View inflate = inflater.inflate(R.layout.fragment_top, container, false);

        input = (EditText) inflate.findViewById(R.id.input);
        sendMessage = (Button) inflate.findViewById(R.id.sendMessage);

        //TODO 点击事件没有完成.
        sendMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String s = input.getText().toString();
                Bundle bundle = new Bundle();
                myListenerTwo.revicerMessage(bundle);
            }
        });

        return inflate;
    }
}
